/* tcp_server.h
 *
 * tcp协议测试服务器
 *
 * Neo-T, 创建于2022.08.18 11:20
 * 版本: 1.0
 *
 */
#ifndef TCP_SERVER_H
#define TCP_SERVER_H

#ifdef SYMBOL_GLOBALS
	#define TCP_SERVER_EXT
#else
	#define TCP_SERVER_EXT extern
#endif //* SYMBOL_GLOBALS
  
#define TCP_CLIENT_NUM 5 //* 最多5个tcp客户端连接

//* tcp客户端控制块
typedef struct _STCB_TCP_CLIENT_ { 
  SOCKET hSock; 
  
  struct {
    in_addr_t unIp; 
    USHORT usPort; 
  } stAddr; 
  
  struct { 
    CHAR bParseState; 
    UCHAR ubaRcvBuf[RCV_BUF_SIZE]; 
    USHORT usWriteIdx; 
    USHORT usReadIdx; 
  } stRcv; 
  
  UINT unLastRcvSecs; 
} STCB_TCP_CLIENT, *PSTCB_TCP_CLIENT; 

TCP_SERVER_EXT SOCKET tcp_server_start(USHORT usSrvPort, USHORT usBacklog); 
TCP_SERVER_EXT void tcp_server_accept(SOCKET hSockSrv); 
TCP_SERVER_EXT PSTCB_TCP_CLIENT tcp_server_get_client(SOCKET hSockClt); 
TCP_SERVER_EXT void tcp_server_clear_inactive_clients(void); 
TCP_SERVER_EXT void tcp_server_read(SOCKET hSockClt); 


#endif
